

#include "system.h"
#include "machine.h"

#ifndef IPT_H2
#define IPT_H2


using namespace std;

//using namespace std;
/*
NOTE: currently added to makefile common under userprog
should check to see if that is where it should be
*/

class IPT
{

 public:

  IPT();
  ~IPT();

  //Refer to IPT.cc for more information about the following functions
  void setElement(int ppn, int vpn, AddrSpace *processID);
  int findPPN(int vpn, AddrSpace * processID);
  void evictFirstSlot();
  void evictRandomSlot();
  void setDirtyBit(int vpn);
  void setUseBit(int vpn);
  void clearElement(int vpn);
  void clearProcessElements(AddrSpace *processID);
  void printiptElements();

  int lastAddrspace; //Address space of last thread
 private:

struct IPTElement
{
	int virtualPage;    // The page number in virtual memory.
	int physicalPage;   // The page number in real memory (relative to the
	//  start of "mainMemory"3
	bool valid;         // If this bit is set, the translation is ignored.
	// (In other words, the entry hasn't been initialized.)
	bool readOnly;      // If this bit is set, the user program is not allowed
	// to modify the contents of the page.
	
	bool use;           // This bit is set by the hardware every time the
	// page is referenced or modified.
	
	bool dirty;         // This bit is set by the hardware every time the
	// page is modified.
	
	int PageType; //not used
	
	AddrSpace *processID; //ID of process
	
	int TimeStamp; //not used
};


 IPTElement iptElement[NumPhysPages]; //IPT elements
  Lock *iptLock; //Lock for the IPT to prevent race condition
  int evictSlot;
};


#endif
